package com.fiap.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import com.fiap.dao.VeiculoDAO;
import com.fiap.to.VeiculoTO;

public class VeiculoDAOImpl extends DAOImpl<VeiculoTO, Integer> implements VeiculoDAO{

	public VeiculoDAOImpl(EntityManager entityManager) {
		super(entityManager);
	}

	@Override
	public List<VeiculoTO> buscarVeiculoPorPlaca(String placa) {
		TypedQuery<VeiculoTO> query = em.createQuery("from VeiculoTO s where s.placa like :c", VeiculoTO.class);
		query.setParameter("c", placa);
		return query.getResultList();
	}

	@Override
	public List<VeiculoTO> buscarVeiculoPorId(int id) {
		TypedQuery<VeiculoTO> query = em.createQuery("from VeiculoTO s where s.dono.id_cliente = :c", VeiculoTO.class);
		query.setParameter("c", id);
		return query.getResultList();
	}

	@Override
	public List<VeiculoTO> buscarTodosCarros() {
		TypedQuery<VeiculoTO> query = em.createQuery("from VeiculoTO", VeiculoTO.class);
		return query.getResultList();
	}

}
